package edu.hit.pact.pgse.ch;

/**
 *
 * Copyright Pact Lab of H.I.T.
 *
 * Designed and Implemented by Grid Researching Group, 
 * Pact Lab, Harbin
 * 
 * This Project is part of the national 973 Project:
 * Internet Based Virtual Computing Environment
 *
 * http://pact518.hit.edu.cn
 * 
 * Author:       Meteor <meteorlxk@gmail.com> 
 * Copyright:    pact518 
 * Version:      1.0
 * Created:      2009-4-9 
 * LastModified: 2009-4-9
 */

import edu.hit.pact.pgse.util.Md5Sum;

/**
 * @author Meteor
 * 
 */
public class KetamaHashFunction implements HashFunction {

	/*
	 * (non-Javadoc)
	 * 
	 * @see HashFunction#hash(java.lang.Object)
	 */
	@Override
	public int hash(Object o) {
		byte[] bKey = Md5Sum.getMd5sum(o.toString());
		
		int rv = ((bKey[3] & 0xFF) << 24) | ((bKey[2] & 0xFF) << 16)
				| ((bKey[1] & 0xFF) << 8) | (bKey[0] & 0xFF);

		return rv;
	}
}
